<!--字典类型-->
<script setup lang="ts">
import {getOrderPrinterTasks} from "@/api/order";
import {PrinterTaskForm, PrinterTaskPageVo, PrinterTaskQuery} from "@/api/order/types";
import {orderPrinterTypeOptions, statusOpt2} from "@/utils/status";

defineOptions({
  name: "PrinterTask",
  inheritAttrs: false,
});

const queryFormRef = ref(ElForm);
const dataFormRef = ref(ElForm);


const loading = ref(false);
const ids = ref<number[]>([]);
const total = ref(0);
const statusOptions = statusOpt2();
const printer_types = orderPrinterTypeOptions();

const queryParams = reactive<PrinterTaskQuery>({
  pageNum: 1,
  pageSize: 20,
});
const taskList = ref<PrinterTaskPageVo[]>();
const dialog = reactive({
  title: "",
  visible: false,
});
const formData = reactive<PrinterTaskForm>({
  status: 1
});
const rules = reactive({});

/** 查询 */
function handleQuery() {
  loading.value = true;
  getOrderPrinterTasks(queryParams)
    .then(({data}) => {
      taskList.value = data.items;
      total.value = data.total;
    })
    .finally(() => {
      loading.value = false;
    });
}

/**
 * 重置查询
 */
function resetQuery() {
  queryFormRef.value.resetFields();
  queryParams.pageNum = 1;
  handleQuery();
}

onMounted(() => {
  handleQuery();
});
</script>

<template>
  <div class="app-container">
    <div class="search-container">
      <el-form ref="queryFormRef" :model="queryParams" :inline="true">
        <el-form-item label="关键字" prop="name">
          <el-input
            v-model="queryParams.keywords"
            placeholder="字典类型名称/编码"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery()"
          >
            <i-ep-search/>
            搜索
          </el-button
          >
          <el-button @click="resetQuery()">
            <i-ep-refresh/>
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <el-table
        v-loading="loading"
        highlight-current-row
        :data="taskList"
      >
        <el-table-column label="ID" prop="id"/>
        <el-table-column label="任务名称" prop="title"/>
        <el-table-column label="打印机" prop="printer_title"/>
        <el-table-column label="打印数量" prop="printer_amount">
          <template #default="scope">
            {{ scope.row.print_amount }} / {{ scope.row.amount }}
          </template>
        </el-table-column>
        <el-table-column label="店铺名称" prop="shop_title"/>
        <el-table-column label="状态" align="center" width="100">
          <template #default="scope">
            <el-tag :type="statusOptions[scope.row.status].type">
              {{ statusOptions[scope.row.status].title }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="create_time" align="center"/>
      </el-table>

      <pagination
        v-if="total > 0"
        v-model:total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="handleQuery"
        class="pull-right"
        style="margin: 15px 0px;"
      />
    </el-card>
  </div>
</template>
